package com.beerq.wxapi;


import android.content.Intent;
import android.os.Bundle;

import com.beerq.util.Constants;
import com.beerq.util.LogX;
import com.beerq.view.BaseActivity;
import com.beerq.view.purchase.PaySucceedActivity;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;


public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;

    public static BaseResp baseRsp=null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LogX.trace(TAG,"onCreate");
        Constants.getWXAPI(this).handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {

        LogX.trace(TAG,"onReq");

	}

	@Override
	public void onResp(BaseResp resp) {

        LogX.trace(TAG,"resp="+resp.errCode);





		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

            baseRsp=resp;
            switch (resp.errCode) {
                case BaseResp.ErrCode.ERR_OK:
                    Intent intent=new Intent(this, PaySucceedActivity.class);
                    startActivity(intent);
                    finish();
                    break;
                case BaseResp.ErrCode.ERR_USER_CANCEL:
//                result = R.string.errcode_cancel;
                    showToast("取消支付");

                case BaseResp.ErrCode.ERR_AUTH_DENIED:
//                result = R.string.errcode_deny;
                    break;
                case BaseResp.ErrCode.ERR_UNSUPPORT:
//                result = R.string.errcode_unsupported;
                    break;
                default:
//                result = R.string.errcode_unknown;
                    break;
            }






            finish();

//			AlertDialog.Builder builder = new AlertDialog.Builder(this);
//			builder.setTitle(R.string.beerq_warm_tip);
////			builder.setMessage(R.string.beerq_lq_tips, String.valueOf(resp.errCode)));
//			builder.show();
		}
	}
}